package com.example.statistics.ui.yw

import com.example.statistics.bean.DefineInputBean
import com.example.statistics.bean.yw.ProductTypeBean
import com.example.statistics.common.BaseInputActivity
import com.example.statistics.ex.isNumber
import com.example.statistics.ex.mulEx
import com.example.statistics.ex.textStringToNumber
import com.example.statistics.net.UrlConfig
import com.example.statistics.utils.Constants
import com.example.statistics.weight.TextProcessingView

/**
 * 成品销售
 */
class ProductSalesActivity : BaseInputActivity<ProductTypeBean>() {

    var finishedProduct: ProductTypeBean? = null

    override val title: String
        get() = "依汶成品出售"

    override val url: String
        get() = UrlConfig.YW_PRODUCT_SALES_ADD

    override fun initialize() {
        super.initialize()
        finishedProduct = intent.getSerializableExtra(Constants.DATA) as ProductTypeBean?
        finishedProduct?.let {
            extentParams.add("productId" to it.ID)
            extentParams.add("productBrand" to it.productBrand)
            extentParams.add("productName" to it.productName)
        }
    }

    override val inputDataList: List<DefineInputBean>
        get() = listOf(
            DefineInputBean(
                "日期：", "date", TextProcessingView.STYLE_DATE,
            ),
            DefineInputBean(
                "品牌：", "", TextProcessingView.STYLE_DISPLAY,
                labelValue = finishedProduct?.productBrand
            ),
            DefineInputBean(
                "商品：", "", TextProcessingView.STYLE_DISPLAY,
                labelValue = finishedProduct?.productName
            ),
            DefineInputBean(
                "规格：", "specification", TextProcessingView.STYLE_DISPLAY,
                labelValue = finishedProduct?.specification?.toString()
            ),
           /* DefineInputBean(
                "数量：", "salesNumber", TextProcessingView.STYLE_INPUT_FLOAT,
                afterTextChangeListener = { str, list ->
                    if (str.isNumber() && list["specification"]?.contentText.isNumber()) {
                        val specification = list["specification"]?.textStringToNumber
                        list["salesWeight"]?.contentText = specification.mulEx(str.toDouble()).toString()
                    } else {
                        list["salesWeight"]?.contentText = ""
                    }
                }
            ),
            DefineInputBean(
                "重量：", "salesWeight", TextProcessingView.STYLE_INPUT_FLOAT,
                afterTextChangeListener = { str, list ->
                    if (str.isNumber() && list["salesPrice"]?.contentText.isNumber()) {
                        val salesPrice = list["salesPrice"]?.textStringToNumber
                        list["totalPrice"]?.contentText = salesPrice.mulEx(str.toDouble()).toString()
                    } else {
                        list["totalPrice"]?.contentText = ""
                    }
                }
            ),
            DefineInputBean(
                "单价：", "salesPrice", TextProcessingView.STYLE_INPUT_FLOAT,
                afterTextChangeListener = { str, list ->
                    if (str.isNumber() && list["salesWeight"]?.contentText.isNumber()) {
                        val salesWeight = list["salesWeight"]?.textStringToNumber
                        list["totalPrice"]?.contentText = salesWeight.mulEx(str.toDouble()).toString()
                    } else {
                        list["totalPrice"]?.contentText = ""
                    }
                }
            ),*/
            DefineInputBean(
                "总价：", "totalPrice", TextProcessingView.STYLE_DISPLAY
            ),
            DefineInputBean(
                "客户：", "customer", TextProcessingView.STYLE_INPUT
            ),
        )
}